<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    let value = 0;

    function recursion(...rest) {
        rest.map(item => {
            value += item
        })
        recursion.valueOf = function() {
            let oldvalue = value;
            value = 0
            return oldvalue
        }
        return recursion
    }

    console.log(recursion(1)(1, 2, 3).valueOf());
    console.log(recursion(1, 2)(1, 2, 3).valueOf());
</script>

</html>